/*     */ package com.zimbra.cs.account.accesscontrol;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.SetUtil;
/*     */ import java.util.HashSet;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ComboRight
/*     */   extends AdminRight
/*     */ {
/*  27 */   private Set<Right> mRights = new HashSet();
/*     */   
/*     */ 
/*  30 */   private Set<Right> mAllRights = new HashSet();
/*     */   
/*     */ 
/*  33 */   private Set<Right> mPresetRights = new HashSet();
/*     */   
/*     */ 
/*  36 */   private Set<AttrRight> mAttrRights = new HashSet();
/*     */   
/*     */   ComboRight(String name) {
/*  39 */     super(name, Right.RightType.combo);
/*     */   }
/*     */   
/*     */   public boolean isComboRight()
/*     */   {
/*  44 */     return true;
/*     */   }
/*     */   
/*     */   public String dump(StringBuilder sb) {
/*  48 */     super.dump(sb);
/*     */     
/*  50 */     sb.append("===== combo right properties: =====\n");
/*     */     
/*  52 */     sb.append("rights:\n");
/*  53 */     for (Right r : this.mRights) {
/*  54 */       sb.append("    ");
/*  55 */       sb.append(r.getName());
/*  56 */       sb.append("\n");
/*     */     }
/*     */     
/*  59 */     return sb.toString();
/*     */   }
/*     */   
/*     */   void addRight(Right right) throws ServiceException
/*     */   {
/*  64 */     if (right.isUserRight())
/*  65 */       throw ServiceException.FAILURE("internal error", null);
/*  66 */     this.mRights.add(right);
/*     */   }
/*     */   
/*     */   boolean overlaps(Right other)
/*     */     throws ServiceException
/*     */   {
/*  72 */     for (Right r : getAllRights())
/*     */     {
/*     */ 
/*  75 */       if (r.overlaps(other))
/*  76 */         return true;
/*     */     }
/*  78 */     return false;
/*     */   }
/*     */   
/*     */   boolean executableOnTargetType(TargetType targetType)
/*     */   {
/*  83 */     return true;
/*     */   }
/*     */   
/*     */   boolean isValidTargetForCustomDynamicGroup()
/*     */   {
/*  88 */     for (Right right : getAllRights()) {
/*  89 */       if (!right.isValidTargetForCustomDynamicGroup()) {
/*  90 */         return false;
/*     */       }
/*     */     }
/*  93 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   boolean grantableOnTargetType(TargetType targetType)
/*     */   {
/* 101 */     for (Right r : getAllRights()) {
/* 102 */       if (!r.grantableOnTargetType(targetType)) {
/* 103 */         return false;
/*     */       }
/*     */     }
/* 106 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   boolean allowSubDomainModifier()
/*     */   {
/* 113 */     for (Right r : getAllRights()) {
/* 114 */       if (r.executableOnTargetType(TargetType.domain)) {
/* 115 */         return true;
/*     */       }
/*     */     }
/* 118 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   boolean allowDisinheritSubGroupsModifier()
/*     */   {
/* 125 */     for (Right r : getAllRights()) {
/* 126 */       if ((r.executableOnTargetType(TargetType.dl)) || (r.executableOnTargetType(TargetType.account)) || (r.executableOnTargetType(TargetType.calresource)))
/*     */       {
/*     */ 
/* 129 */         return true;
/*     */       }
/*     */     }
/* 132 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   Set<TargetType> getGrantableTargetTypes()
/*     */   {
/* 139 */     Set<TargetType> targetTypes = null;
/* 140 */     for (Right r : getAllRights()) {
/* 141 */       Set<TargetType> tts = r.getGrantableTargetTypes();
/* 142 */       if (targetTypes == null) {
/* 143 */         targetTypes = tts;
/*     */       } else {
/* 145 */         targetTypes = SetUtil.intersect(targetTypes, tts);
/*     */       }
/*     */     }
/* 148 */     return targetTypes;
/*     */   }
/*     */   
/*     */   void setTargetType(TargetType targetType) throws ServiceException
/*     */   {
/* 153 */     throw ServiceException.FAILURE("target type is now allowed for combo right", null);
/*     */   }
/*     */   
/*     */   void verifyTargetType()
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */   public TargetType getTargetType() throws ServiceException
/*     */   {
/* 162 */     throw ServiceException.FAILURE("internal error", null);
/*     */   }
/*     */   
/*     */   public String getTargetTypeStr()
/*     */   {
/* 167 */     return null;
/*     */   }
/*     */   
/*     */   void completeRight() throws ServiceException
/*     */   {
/* 172 */     super.completeRight();
/*     */     
/* 174 */     expand(this, this.mPresetRights, this.mAttrRights);
/* 175 */     this.mAllRights.addAll(this.mPresetRights);
/* 176 */     this.mAllRights.addAll(this.mAttrRights);
/*     */   }
/*     */   
/*     */   private static void expand(ComboRight right, Set<Right> presetRights, Set<AttrRight> attrRights) throws ServiceException
/*     */   {
/* 181 */     for (Right r : right.getRights()) {
/* 182 */       if (r.isPresetRight()) {
/* 183 */         presetRights.add(r);
/* 184 */       } else if (r.isAttrRight()) {
/* 185 */         attrRights.add((AttrRight)r);
/* 186 */       } else if (r.isComboRight()) {
/* 187 */         expand((ComboRight)r, presetRights, attrRights);
/*     */       } else
/* 189 */         throw ServiceException.FAILURE("internal error", null);
/*     */     }
/*     */   }
/*     */   
/*     */   boolean containsPresetRight(Right right) {
/* 194 */     return this.mPresetRights.contains(right);
/*     */   }
/*     */   
/*     */   Set<Right> getPresetRights()
/*     */   {
/* 199 */     return this.mPresetRights;
/*     */   }
/*     */   
/*     */   Set<AttrRight> getAttrRights()
/*     */   {
/* 204 */     return this.mAttrRights;
/*     */   }
/*     */   
/*     */   public Set<Right> getRights()
/*     */   {
/* 209 */     return this.mRights;
/*     */   }
/*     */   
/*     */   public Set<Right> getAllRights()
/*     */   {
/* 214 */     return this.mAllRights;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/accesscontrol/ComboRight.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */